﻿<!-- #include file="Admin_Onlogin.asp" -->
<!--#include file="ASPJson.class.asp"-->
<!--#include file="Uploader.class.asp"-->
<!--#include file="Draw.asp"-->
<%
Private Function adddb(byval t0,byval t1,byval t2,byval t3,byval t4,byval t5,byval t6,byval t7,byval t8,byval t9,byval t10)
	ID = GetNewID("Attachment", "ID")
	insert "Attachment",array(array("ID",ID,0,0),array("ChannelID",t10,0,0),array("classid",t9,0,0),array("cid",t8,0,0),array("filepath",t0,255,1),array("filename",t1,255,1),array("filesize",GetSizeNo(getnum(t2),"k"),255,1),array("oldname",Replace(t3, "."&t4, "", 1, -1, 1),255,1),array("fileext",t4,50,1),array("ispic",Is_Pic("."&t4),1,0),array("createip",getip,255,1),array("createdate",t5,255,0),array("adminid",t6,0,0),array("userid",t7,0,0),array("fullname",t0&t1,0,1))
	if Is_Pic(t1)=1 then
		dim draw
		set draw=new cms_draw
		draw.add t0&t1
		set draw=nothing
	end if
End Function

Function ReplaceTime(s_Time, s_Patt)
	If IsDate(s_Time) = False Then
		ReplaceTime = ""
		Exit Function
	End If
	Dim ret
	ret = s_Patt
	Dim y1, y2, m1, m2, d1, d2, h1, h2, i1, i2, s1, s2
	y2 = CStr(Year(s_Time))
	y1 = Right(y2, 2)
	m1 = CStr(Month(s_Time))
	m2 = Right("0" & m1, 2)
	d1 = CStr(Day(s_Time))
	d2 = Right("0" & d1, 2)
	h1 = CStr(Hour(s_Time))
	h2 = Right("0" & h1, 2)
	i1 = CStr(Minute(s_Time))
	i2 = Right("0" & i1, 2)
	s1 = CStr(Second(s_Time))
	s2 = Right("0" & s1, 2)
	ret = Replace(ret, "{yyyy}", y2, 1, -1, 1)
	ret = Replace(ret, "{yy}", y1, 1, -1, 1)
	ret = Replace(ret, "{mm}", m2, 1, -1, 1)
	ret = Replace(ret, "{m}", m1, 1, -1, 1)
	ret = Replace(ret, "{dd}", d2, 1, -1, 1)
	ret = Replace(ret, "{d}", d1, 1, -1, 1)
	ret = Replace(ret, "{hh}", h2, 1, -1, 1)
	ret = Replace(ret, "{h}", h1, 1, -1, 1)
	ret = Replace(ret, "{ii}", i2, 1, -1, 1)
	ret = Replace(ret, "{i}", i1, 1, -1, 1)
	ret = Replace(ret, "{ss}", s2, 1, -1, 1)
	ret = Replace(ret, "{s}", s1, 1, -1, 1)
	ReplaceTime = ret
End Function

if AdminID="" then
	Response.Write "{""url"":"""",""original"":"""",""title"":"""",""state"":""登录失败""}"
	Response.End()
end if
dim sqltime:sqltime="now()"
if SystemDatabaseType = 1 then sqltime="GetDate()"
dim cid
ChannelID = Code_CLng(Trim(Request.QueryString("channelid")))
classid = Code_CLng(Trim(Request.QueryString("classid")))
cid = Code_CLng(Trim(Request.QueryString("cid")))
If ChannelID = "" Then ChannelID = 0
If ChannelID > 0 Then
	Call GetChannel(ChannelID)
	MaxFileSize=ChannelMaxFileSize
	UploadDir = InstallDir & UploadSetting(1) & "/" & Trim(ChannelUploadDir) & "/" & UploadSetting(2)
	UploadList = InstallDir & UploadSetting(1) & "/" & Trim(ChannelUploadDir) & "/" & ReplaceTime(Now(), UploadSetting(2))
	UploadFiletype = ChannelUpFileType(0)
Else
	MaxFileSize=UploadSetting(21)
	UploadDir = InstallDir & UploadSetting(1) & "/UEditor/" & UploadSetting(2)
	UploadList = InstallDir & UploadSetting(1) & "/UEditor/" & ReplaceTime(Now(), UploadSetting(2))
	UploadFiletype = UploadSetting(3)
End If

Set up = new Uploader
up.MaxSize = MaxFileSize*1000
up.FileField = "upfile"
up.PathFormat = UploadDir & "{time}{rand:6}"

up.UploadBase64("scrawl.png")

adddb UploadList,Right( up.FilePath, Len(up.FilePath) - InStrRev(up.FilePath, "/") ),up.Filesize,up.OriginalFileName,Replace(Right( up.FilePath, Len(up.FilePath) - InStrRev(up.FilePath, ".") + 1 ), ".", "", 1, -1, 1),sqltime,AdminID,0,cid,classid,ChannelID

Set json = new ASPJson

With json.data
	.Add "url", up.FilePath
	.Add "original", Replace(up.OriginalFileName, Right( up.FilePath, Len(up.FilePath) - InStrRev(up.FilePath, ".") + 1 ), "", 1, -1, 1)
	.Add "state", up.State
	.Add "title", up.OriginalFileName
End With

json.PrintJson()
%>